home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-23 | 1.6 KB | 65 lines | [TEXT/PJMM] |
- {The sprite unit for SATminimal}
-
- unit sMySprite;
-
- interface
- uses
- SAT, FaceSetFromPICT;
- var
- theSound: Handle;
- faces: array[0..5] of FacePtr;
-
- procedure InitMySprite;
- procedure SetupMySprite (me: SpritePtr);
- procedure HandleMySprite (me: SpritePtr);
-
- implementation
-
- procedure MyFaceHandler (theFace: FacePtr; index: integer);
- begin
- faces[index - 2] := theFace;
- end;
-
- {Initialization of variables used by the sprite unit}
- procedure InitMySprite;
- var
- i: integer;
- begin
- {Preload the sound}
- theSound := SATGetSound(128);
- {Preload all icons used by the sprites - 6 of them}
- GetFaceSetFromPICT(128, 130, 131, 132, @MyFaceHandler);
- {for i := 0 to 5 do}
- {faces[i] := SATGetFace(128 + i);}
- end;
-
- {Initialize a new sprite}
- procedure SetupMySprite (me: SpritePtr);
- begin
- me^.mode := 0; {Pick a valid face number}
- me^.speed.h := 2; {Set the speed - only horizontal is used here }
- me^.task := @HandleMySprite; {Set a handling routine. MANDATORY! If nil, the sprite will self-destruct.}
- end;
-
- {Define the behaviour of a sprite}
- procedure HandleMySprite (me: SpritePtr);
- begin
- {Select a face. We use me^.mode as face counter, rotating through them.}
- me^.mode := (me^.mode + 1) mod 6;
- me^.face := faces[me^.mode];
-
- {Move}
- me^.position.h := me^.position.h + me^.speed.h; {Add the speed - horizontal only}
- if me^.position.h > gSAT.offSizeH - 16 then {Turn back if at the right border}
- begin
- me^.speed.h := -2;
- SATSoundPlay(theSound, 1, true);
- end;
- if me^.position.h < -16 then {Turn back if at the left border}
- begin
- me^.speed.h := 2;
- SATSoundPlay(theSound, 1, true);
- end;
- end;
-
- end.